<template>
    <div 
    class="list-item"
    :class="{todo: ['3', '5'].includes(data.shbj)}"
    >
        <div class="left">
            <div class="title">
                <el-checkbox 
                    v-show="batch"
                    v-model="checked"
                    @change="cbChangeHandler"
                    :disabled="!~['7'].indexOf(data.shbj)"
                ></el-checkbox>

                代办详情
            </div>

            <div class="row">
                <div class="text">
                    待办申请：
                    {{data.catypename}}

                    <a 
                    v-if="data.noticeurl"
                    class="notice-link"
                    :href="data.noticeurl"
                    target="_blank"
                    >
                        <i class="el-icon-link"></i>
                        招标公告链接
                    </a>

                    <div 
                    class="notice-link"
                    @click="infoDetailHandler"
                    >
                        <i class="el-icon-files"></i>
                        查看提交资料信息
                    </div>
                </div>
            </div>
            
            <div class="row">
                <div class="text">
                    提交时间：{{data.addtime}}
                </div>
            </div>

            <div class="row" v-if="~['6', '7'].indexOf(data.shbj)">
                <div class="text">
                    邮寄信息：{{data.receive_username}}-{{data.receive_mobile}}-{{data.receive_addr}}
                </div>
            </div>
        </div>
        <div class="right">
            <div class="title">
                <div class="left">
                    状态
                </div>

                <div class="right">
                    
                </div>
            </div>

            <template>
                <div class="row">
                    <div class="text">
                        <span 
                        class="status"
                        >
                            {{getTextByStatus(data.shbj)}}
                        </span>
                    </div>
                </div>
            </template>
            

            <template v-if="data.shbj === '7'">
                <div class="row">
                    <div class="text">
                        邮寄单号：
                    </div>
                    
                    <div class="text">
                        {{data.postcode}}
                    </div>
                </div>

                <div class="row">
                    <div class="text">
                        完成时间：
                    </div>
                    
                    <div class="text">
                        {{data.uptime}}
                    </div>
                </div>
            </template>

            <div class="row">
                <!-- <el-button 
                v-if="data.shbj === '7'"
                size="small"
                type="primary"
                icon="el-icon-delete" 
                @click="delHandler"
                >
                    删除
                </el-button> -->

                <el-button 
                v-if="data.shbj === '3'"
                size="small"
                type="primary"
                icon="el-icon-tickets" 
                @click="completeInfo"
                >
                    电脑端完善信息
                </el-button>

                <el-button 
                v-if="data.shbj === '3'"
                size="small"
                type="primary"
                icon="el-icon-mobile" 
                @click="completeInfoByMobile"
                >
                    手机端完善信息
                </el-button>

                <el-button 
                v-if="data.shbj === '5'"
                size="small"
                type="primary"
                icon="el-icon-tickets" 
                @click="completePostInfo"
                >
                    完善邮寄信息
                </el-button>

                <!-- <el-button 
                v-if="data.shbj === '6'"
                size="small"
                type="primary"
                icon="el-icon-tickets" 
                @click="editPostInfo"
                >
                    修改邮寄信息
                </el-button> -->

                <el-button 
                v-if="data.shbj === '7'"
                size="small"
                type="primary"
                icon="el-icon-tickets" 
                @click="goto('/user/center/order')"
                >
                    申请发票
                </el-button>
            </div>
        </div>

        <my-dialog 
        v-model="dialogVisible"
        :title="dialogTitle"
        :width="dialogWidth"
        >
            <component 
                v-if="dialogVisible"
                :is="dialogComponent" 
                :data="data"
                @close="dialogClose"
            ></component>
        </my-dialog>
    </div>
</template>

<script>
import {getTextByStatus} from '../../../js/status.js';

import FormPost from './form-post';
import FormInfo from './form-info';
import DetailInfoQrcode from './detail-info-qrcode.vue';
import DetailInfo from './detail-info.vue';

export default {
    props: {
        batch: {
            type: Boolean,
            default: false,
        },
        data: {
            type: Object,
            default: () => ({}),
        },
        batchCheck: {
            type: Array,
            default: () => [],
        },
    },
    data() {
        return {
            dialogVisible: false,
            dialogTitle: '',
            dialogComponent: null,
            dialogWidth: '',

            checked: false,
        };
    },
    watch: {
        batchCheck: {
            handler(val) {
                if (!~val.indexOf(this.data)) {
                    this.checked = false;
                }
            }, deep: true,
        }
    },
    methods: {
        // 列表中复选框选中事件
        cbChangeHandler(val) {
            var arr = this.batchCheck,
                guid = this.data;

            if (val) {
                arr.push(guid);
            } else {
                var index = arr.indexOf(guid);

                arr.splice(index, 1);
            }

            this.$emit('update:batchCheck', arr);
        },
        // 删除
        delHandler(row) {
            this.$emit('del', row);
        },
        getTextByStatus,
        dialogClose() {
            this.dialogVisible = false;

            this.$emit('update');
        },
        // 完善信息
        completeInfo() {
            this.dialogTitle = '电脑端完善信息';
            this.dialogWidth = '500px';
            this.dialogComponent = FormInfo;

            this.dialogVisible = true;
        },
        completeInfoByMobile() {
            this.dialogTitle = '手机端完善信息';
            this.dialogWidth = '500px';
            this.dialogComponent = DetailInfoQrcode;

            this.dialogVisible = true;
        },
        // 添加邮寄信息
        completePostInfo() {
            this.dialogTitle = '完善邮寄信息';
            this.dialogWidth = '500px';
            this.dialogComponent = FormPost;

            this.dialogVisible = true;
        },
        editPostInfo() {
            this.dialogTitle = '修改邮寄信息';
            this.dialogWidth = '500px';
            this.dialogComponent = FormPost;

            this.dialogVisible = true;
        },
        infoDetailHandler() {
            this.dialogTitle = '查看提交资料信息';
            this.dialogWidth = '800px';
            this.dialogComponent = DetailInfo;

            this.dialogVisible = true;
        },
    },
};
</script>

<style scoped lang="scss">
    @import '@css/var.scss';

    .list-item{
        overflow: hidden;
        padding: 36px 0;
        cursor: default;
        position: relative;

        & + .list-item:before{
            content: '';
            width: 100%;
            height: 1px;
            background: #f0f0f0;
            position: absolute;
            top: 0;
        }

        .title{
            font-size: 16px;
            color: #333333;
            line-height: 1em;
            overflow: hidden;
            margin-bottom: 16px;

            .left {
                float: left;
                color: #333333;
            }

            .right {
                float: right;

                ::v-deep{
                    .el-button--text{
                        padding: 0;
                    }
                }
            }
        }

        & > .left{
            width: 60%;
            float: left;
        }

        & > .right{
            width: 40%;
            float: left;
        }

        .row{
            color: #666;
            margin-top: 6px;
            overflow: hidden;
            width: 90%;
            line-height: 1em;

            .text{
                float: left;
            }

            & + .row{
                margin-top: 14px;
            }
        }

        .status {
            // color: $dangerColor;
        }
    }

    .notice-link{
        display: inline-block;
        color: $primaryColor;
        margin-left: 1em;
        cursor: pointer;
    }
</style>